package com.dhcc.bpm.modules.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.api.entity.ServiceOutside;
import com.dhcc.bpm.modules.api.service.IServiceOutsideService;
import com.dhcc.bpm.modules.api.vo.ServiceOutsideVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName ServiceOutsideController
 * @Description 后端服务外部调用表 控制器
 * @Author daina
 * @Date 2020/2/25 13:14
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-api/serviceoutside")
@Api(value = "后端服务外部调用表", tags = "后端服务外部调用表接口")
public class ServiceOutsideController extends BladeController {

	private IServiceOutsideService serviceOutsideService;

	/**
	 * @Description 详情
	 * @Author daina
	 * @Date 14:40 2020/2/25
	 * @param serviceOutside
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.api.entity.ServiceOutside>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入serviceOutside")
	public R<ServiceOutside> detail(ServiceOutside serviceOutside) {
		ServiceOutside detail = serviceOutsideService.getOne(Condition.getQueryWrapper(serviceOutside));
		return R.data(detail);
	}

	/**
	 * @Description 后端服务外部调用表
	 * @Author daina
	 * @Date 14:40 2020/2/25
	 * @param serviceOutside
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.entity.ServiceOutside>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "后端服务外部调用分页", notes = "传入serviceOutside")
	@Log(title = "后端服务外部调用分页", businessType = BusinessType.SELECT)
	@ApiLog("后端服务外部调用分页")
	public R<IPage<ServiceOutside>> list(@ApiIgnore @RequestParam Map<String, Object> serviceOutside, Query query) {
		IPage<ServiceOutside> pages = serviceOutsideService.page(Condition.getPage(query), Condition.getQueryWrapper(serviceOutside,ServiceOutside.class));
		return R.data(pages);
	}

	/**
	 * @Description 后端服务外部调用表
	 * @Author daina
	 * @Date 14:40 2020/2/25
	 * @param serviceOutside
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.vo.ServiceOutsideVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入serviceOutside")
	@Log(title = "后端服务外部调用分页", businessType = BusinessType.SELECT)
	@ApiLog("后端服务外部调用分页")
	public R<IPage<ServiceOutsideVO>> page(ServiceOutsideVO serviceOutside, Query query) {
		IPage<ServiceOutsideVO> pages = serviceOutsideService.selectServiceOutsidePage(Condition.getPage(query), serviceOutside);
		return R.data(pages);
	}

	/**
	 * @Description 新增 后端服务外部调用表
	 * @Author daina
	 * @Date 14:40 2020/2/25
	 * @param serviceOutside
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入serviceOutside")
	@Log(title = "新增后端服务外部调用", businessType = BusinessType.INSERT)
	@ApiLog("新增后端服务外部调用")
	public R save(@Valid @RequestBody ServiceOutside serviceOutside) {
		return R.status(serviceOutsideService.save(serviceOutside));
	}

	/**
	 * @Description 修改 后端服务外部调用表
	 * @Author daina
	 * @Date 14:40 2020/2/25
	 * @param serviceOutside
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入serviceOutside")
	@Log(title = "修改后端服务外部调用", businessType = BusinessType.UPDATE)
	@ApiLog("修改后端服务外部调用")
	public R update(@Valid @RequestBody ServiceOutside serviceOutside) {
		return R.status(serviceOutsideService.updateById(serviceOutside));
	}

	/**
	 * @Description 新增或修改 后端服务外部调用表
	 * @Author daina
	 * @Date 14:41 2020/2/25
	 * @param serviceOutside
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入serviceOutside")
	@Log(title = "新增或修改后端服务外部调用", businessType = BusinessType.INSERT)
	@ApiLog("新增或修改后端服务外部调用")
	public R submit(@Valid @RequestBody ServiceOutside serviceOutside) {
		return R.status(serviceOutsideService.saveOrUpdate(serviceOutside));
	}

	
	/**
	 * @Description 删除 后端服务外部调用表
	 * @Author daina
	 * @Date 14:41 2020/2/25
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "删除后端服务外部调用", notes = "传入ids")
	@Log(title = "删除后端服务外部调用", businessType = BusinessType.DELETE)
	@ApiLog("删除后端服务外部调用")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(serviceOutsideService.deleteLogic(Func.toLongList(ids)));
	}

	
}
